﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Data.Linq;

namespace Gap.Bll.BritishGas
{
    [Table(Name = "[BritishGas].[BritishGasHabits]")]
    public class Habits : BaseItem
    {
        public Habits()
        {
        }

        public static Habits CreateInstance(string schoolId, string className, DateTime start, DateTime end)
        {
            Habits tmp = new Habits();
            tmp._SchoolId = schoolId;
            tmp._ClassName = className;
            tmp._Start = new DateTime(start.Year, start.Month, start.Day);
            tmp._End = new DateTime(end.Year, end.Month, end.Day);

            return tmp;
        }

        public static Habits Get(string schoolId, string className, DateTime start, DateTime end)
        {
            BllContext context = new BllContext();
            DateTime tmpStart = new DateTime(start.Year, start.Month, start.Day);
            DateTime tmpEnd = new DateTime(end.Year, end.Month, end.Day);

            var query = from t in context.Habits
                      where t.SchoolId == schoolId && t.ClassName == className && t.Start == tmpStart && t.End == tmpEnd
                      select t;
            if (query.Count() == 1)
            {
                Habits tmp = query.Single();
                return tmp;
            }
            else
                return null ;
        }

        private int _Id;
        [Column(Storage = "_Id", DbType = "Int", CanBeNull=false, IsDbGenerated=true)]
        public int Id
        {
            get { return _Id; }
        }

        private string _SchoolId;
        [Column(Storage = "_SchoolId", DbType = "VarChar(50) NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        public string SchoolId
        {
            get
            {
                return _SchoolId;
            }
        }

        private string _ClassName;
        [Column(Storage = "_ClassName", DbType = "VarChar(50) NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        public string ClassName
        {
            get
            {
                return _ClassName;
            }
        }

        private DateTime _Start;
        [Column(Storage = "_Start", DbType = "DateTime NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        public DateTime Start
        {
            get
            {
                return _Start;
            }
        }

        private DateTime _End;
        [Column(Storage = "_End", DbType = "DateTime NOT NULL", CanBeNull = false, IsPrimaryKey = true)]
        public DateTime End
        {
            get
            {
                return _End;
            }
        }

        private int? _LightBulbsTotal;
        [Column(Storage= "_LightBulbsTotal", DbType="Int", CanBeNull=true)]
        public int? LightBulbsTotal
        {
            get
            {
                return _LightBulbsTotal;
            }
            set
            {
                _LightBulbsTotal = value;
            }
        }

        private int? _LightBulbsLeftOn;
        [Column(Storage = "_LightBulbsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? LightBulbsLeftOn
        {
            get
            {
                return _LightBulbsLeftOn;
            }
            set
            {
                _LightBulbsLeftOn = value;
            }
        }

        private int? _MonitorsTotal;
        [Column(Storage = "_MonitorsTotal", DbType = "Int", CanBeNull = true)]
        public int? MonitorsTotal
        {
            get
            {
                return _MonitorsTotal;
            }
            set
            {
                _MonitorsTotal = value;
            }
        }

        private int? _MonitorsLeftOn;
        [Column(Storage = "_MonitorsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? MonitorsLeftOn
        {
            get
            {
                return _MonitorsLeftOn;
            }
            set
            {
                _MonitorsLeftOn = value;
            }
        }

        private int? _ComputersTotal;
        [Column(Storage = "_ComputersTotal", DbType = "Int", CanBeNull = true)]
        public int? ComputersTotal
        {
            get
            {
                return _ComputersTotal;
            }
            set
            {
                _ComputersTotal = value;
            }
        }

        private int? _ComputersLeftOn;
        [Column(Storage = "_ComputersLeftOn", DbType = "Int", CanBeNull = true)]
        public int? ComputersLeftOn
        {
            get
            {
                return _ComputersLeftOn;
            }
            set
            {
                _ComputersLeftOn = value;
            }
        }

        private int? _PrintersTotal;
        [Column(Storage = "_PrintersTotal", DbType = "Int", CanBeNull = true)]
        public int? PrintersTotal
        {
            get
            {
                return _PrintersTotal;
            }
            set
            {
                _PrintersTotal = value;
            }
        }

        private int? _PrintersLeftOn;
        [Column(Storage = "_PrintersLeftOn", DbType = "Int", CanBeNull = true)]
        public int? PrintersLeftOn
        {
            get
            {
                return _PrintersLeftOn;
            }
            set
            {
                _PrintersLeftOn = value;
            }
        }

        private int? _WhiteBoardsTotal;
        [Column(Storage = "_WhiteBoardsTotal", DbType = "Int", CanBeNull = true)]
        public int? WhiteBoardsTotal
        {
            get
            {
                return _WhiteBoardsTotal;
            }
            set
            {
                _WhiteBoardsTotal = value;
            }
        }

        private int? _WhiteBoardsLeftOn;
        [Column(Storage = "_WhiteBoardsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? WhiteBoardsLeftOn
        {
            get
            {
                return _WhiteBoardsLeftOn;
            }
            set
            {
                _WhiteBoardsLeftOn  = value;
            }
        }

        private int? _DeskLampsTotal;
        [Column(Storage = "_DeskLampsTotal", DbType = "Int", CanBeNull = true)]
        public int? DeskLampsTotal
        {
            get
            {
                return _DeskLampsTotal;
            }
            set
            {
                _DeskLampsTotal = value;
            }
        }

        private int? _DeskLampsLeftOn;
        [Column(Storage = "_DeskLampsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? DeskLampsLeftOn
        {
            get
            {
                return _DeskLampsLeftOn;
            }
            set
            {
                _DeskLampsLeftOn = value;
            }
        }

        private int? _TelevisionsTotal;
        [Column(Storage = "_TelevisionsTotal", DbType = "Int", CanBeNull = true)]
        public int? TelevisionsTotal
        {
            get
            {
                return _TelevisionsTotal;
            }
            set
            {
                _TelevisionsTotal = value;
            }
        }

        private int? _TelevisionsLeftOn;
        [Column(Storage = "_TelevisionsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? TelevisionsLeftOn
        {
            get
            {
                return _TelevisionsLeftOn;
            }
            set
            {
                _TelevisionsLeftOn = value;
            }
        }

        private int? _DVDsTotal;
        [Column(Storage = "_DVDsTotal", DbType = "Int", CanBeNull = true)]
        public int? DVDsTotal
        {
            get
            {
                return _DVDsTotal;
            }
            set
            {
                _DVDsTotal = value;
            }
        }

        private int? _DVDsLeftOn;
        [Column(Storage = "_DVDsLeftOn", DbType = "Int", CanBeNull = true)]
        public int? DVDsLeftOn
        {
            get
            {
                return _DVDsLeftOn;
            }
            set
            {
                _DVDsLeftOn = value;
            }
        }

        private float? _SickRoomAverage;
        [Column(Storage = "_SickRoomAverage", DbType= "Decimal (5,2)", CanBeNull=true)]
        public float? SickRoomAverage
        {
            get { return _SickRoomAverage; }
            set { _SickRoomAverage = value; }
        }

        private float? _ClassRoomAverage;
        [Column(Storage = "_ClassRoomAverage", DbType= "Decimal (5,2)", CanBeNull=true)]
        public float? ClassRoomAverage
        {
            get { return _ClassRoomAverage; }
            set { _ClassRoomAverage = value; }
        }

        private float? _HallsAverage;
        [Column(Storage = "_HallsAverage", DbType= "Decimal (5,2)", CanBeNull=true)]
        public float? HallsAverage
        {
            get { return _HallsAverage; }
            set { _HallsAverage = value; }
        }

        private float? _WaterAverage;
        [Column(Storage = "_WaterAverage", DbType= "Decimal (5,2)", CanBeNull=true)]
        public float? WaterAverage
        {
            get { return _WaterAverage; }
            set { _WaterAverage = value; }
        }

        private bool _HeatingOn;
        [Column(Storage = "_HeatingOn", DbType= "bit", CanBeNull=true)]
        public bool HeatingOn
        {
            get { return _HeatingOn; }
            set { _HeatingOn = value; }
        }

        private int? _WindowsTotal;
        [Column(Storage = "_WindowsTotal", DbType = "Int", CanBeNull = true)]
        public int? WindowsTotal
        {
            get
            {
                return _WindowsTotal;
            }
            set
            {
                _WindowsTotal = value;
            }
        }

        private int? _WindowsOpen;
        [Column(Storage = "_WindowsOpen", DbType = "Int", CanBeNull = true)]
        public int? WindowsOpen
        {
            get
            {
                return _WindowsOpen;
            }
            set
            {
                _WindowsOpen = value;
            }
        }
      
        private int? _InternalDoorsTotal;
        [Column(Storage = "_InternalDoorsTotal", DbType = "Int", CanBeNull = true)]
        public int? InternalDoorsTotal
        {
            get
            {
                return _InternalDoorsTotal;
            }
            set
            {
                _InternalDoorsTotal = value;
            }
        }
	
        private int? _InternalDoorsOpen;
        [Column(Storage = "_InternalDoorsOpen", DbType = "Int", CanBeNull = true)]
        public int? InternalDoorsOpen
        {
            get
            {
                return _InternalDoorsOpen;
            }
            set
            {
                _InternalDoorsOpen = value;
            }
        }

        private int? _ExternalDoorsTotal;
        [Column(Storage = "_ExternalDoorsTotal", DbType = "Int", CanBeNull = true)]
        public int? ExternalDoorsTotal
        {
            get
            {
                return _ExternalDoorsTotal;
            }
            set
            {
                _ExternalDoorsTotal = value;
            }
        }
	
        private int? _ExternalDoorsOpen;
        [Column(Storage = "_ExternalDoorsOpen", DbType = "Int", CanBeNull = true)]
        public int? ExternalDoorsOpen
        {
            get
            {
                return _ExternalDoorsOpen;
            }
            set
            {
                _ExternalDoorsOpen = value;
            }
        }
	
        private int? _RadiatorsTotal;
        [Column(Storage = "_RadiatorsTotal", DbType = "Int", CanBeNull = true)]
        public int? RadiatorsTotal
        {
            get
            {
                return _RadiatorsTotal;
            }
            set
            {
                _RadiatorsTotal = value;
            }
        }

        private int? _RadiatorsObstructed;
        [Column(Storage = "_RadiatorsObstructed", DbType = "Int", CanBeNull = true)]
        public int? RadiatorsObstructed
        {
            get
            {
                return _RadiatorsObstructed;
            }
            set
            {
                _RadiatorsObstructed = value;
            }
        }


        private object _ConcurencyId;
        [Column(Storage = "_ConcurencyId", DbType = "RowVersion", CanBeNull = false, IsVersion=true)]
        public object ConcurencyId
        {
            get
            {
                return _ConcurencyId;
            }
        }

        public void Delete()
        {
            if(Id > 0)
            {
                BllContext context = new BllContext();
                context.Habits.Attach(this, true);
                context.Habits.DeleteOnSubmit(this);
                context.SubmitChanges();
            }
        }

        public void Update()
        {
            BllContext context = new BllContext();
            if (this.Id == 0)
            {
                context.Habits.InsertOnSubmit(this);
            }
            else
            {
                context.Habits.Attach(this, true);
            }
            context.SubmitChanges();
        }
    }
}
